home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / Music / B / Balthazar src 1.0.sit / Twiddle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-17  |  1.4 KB  |  44 lines  |  [TEXT/KAHL]

  1. /*______________________________________________________________________
  2.  | _|_                                                                    |
  3.  |  ¿  Craig's Lib:Twiddle.c                    Started:    08/21/92    |
  4.  |                                            Last Modified:    10/13/92    |
  5.  |                                                                          |
  6.  | Copyright © 1991 by Craig A. Marciniak          All rights reserved. |
  7.  _______________________________________________________________________*/
  8.  
  9. #include "twiddle.h"
  10.  
  11. /*______________________________________________________________________*/
  12. /* This is a killer little function to get a range of bits from a byte  */
  13. /* You simply pass the value as x, were to start as p,and how many bits */
  14. /* to the left you want.                                 C.A.M. 12/3/92 */
  15. /*______________________________________________________________________*/
  16.  
  17. unsigned getbits(unsigned x,int p,int n)
  18. {
  19.     return (x>>(p+1-n)) & ~(~0 <<n);
  20. }
  21.  
  22. /*___________________ long byte swap for Intell <-> Motorola Conversions*/
  23.  
  24. unsigned long longswap(unsigned long ul)
  25. {
  26.     return (ul >> 24) | ((ul >> 8) & 0xff00) | ((ul << 8) & 0xff0000) | (ul << 24);
  27. }
  28.  
  29. /*___________________ word byte swap for Intell <-> Motorola Conversions*/
  30.  
  31. unsigned short shrtswap(unsigned int us)
  32. {
  33.     return ((us >> 8) | (us << 8)) & 0xffff;
  34. }
  35.  
  36. /*_________________________________________________ Pascal String Copy _*/
  37.  
  38. void PStrCpy(register StringPtr p1, register StringPtr p2)
  39. {
  40.     if (p1 && p2)
  41.         BlockMove(p1, p2, (long) (*p1 + 1));
  42. }
  43.  
  44. /*_______________________________________________________________________*/